package com.woniuxy.commons;

import lombok.Data;

import java.util.List;
import java.util.Set;

@Data
public class Result<T> {

    private Boolean flag;//用于标记当前请求是否成功
    private Integer code;//响应状态码
    private String message;//用于描述当前操作的信息
    private T data;//用于设置给前端返回的真实数据


   public static Result<?> getInstance(){
       Result<?> rs = new Result<>();
        rs.setCode(200);
        rs.setMessage("访问成功");
        return rs;
   }

   public static <S> Result<S> getInstance(Class<S> type){
       Result<S> re = new Result<>();
       re.setCode(200);
       re.setMessage("访问成功");
       return re;
   }

    public static <S> Result<List<S>> getInstanceList(Class<S> type){
        Result<List<S>> listResult = new Result<>();
        listResult.setCode(200);
        listResult.setMessage("访问成功");
        return listResult;
    }

    public static <S> Result<Set<S>> getInstanceSet(Class<S> type){
        Result<Set<S>> setResult = new Result<>();
        setResult.setCode(200);
        setResult.setMessage("访问成功");
        return setResult;
    }

    public Integer getCode() {
        return code;
    }

    public Result<T> setCode(Integer code){
        this.code=code;
        return  this;
    }

    public String getMsg() {
       return message;
    }

    public Result<T> setMsg(String message){
        this.message=message;
        return  this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }
}
